<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%
	String userName = (String) session.getAttribute("userName");
	if (userName != null) {
		response.sendRedirect("user/");
	}
%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>

<title>注册_OR_登录</title>
<meta http-equiv="pragma" content="no-cache" />
<meta http-equiv="cache-control" content="no-cache" />
<link rel="stylesheet" type="text/css" href="css/GlobalSet.css" />
<link rel="stylesheet" type="text/css" href="css/registe.css" />
<link rel="stylesheet" type="text/css" href="css/jqueryInputTips.css" />
<script type="text/javascript" src="js/jquery-1.7.2.min.js">
	
</script>
<script type="text/javascript" src="js/jqueryInputTips.js">
	
</script>
<script type="text/javascript" src="js/GlobalFunction.js">
	
</script>
<script type="text/javascript" src="js/registe.js">
	
</script>
</head>
<body>
	<jsp:include page="header.jsp"></jsp:include>
	<div class="navBar">
		<ul id="navBarLogo">
		</ul>
		<ul id="navBarLink">
			<li><a href="index.jsp">首页</a><span></span></li>
			<li><a href="seller.jsp">店家</a><span></span></li>
			<li><a href="tuangou.jsp">团购</a><span></span>
			</li>
		</ul>
	</div>
	<div class="section">

		<%
			String action = request.getParameter("action");
			if ("registe".equals(action)) {
		%>
		<div class="midBody">
			<div class="secondNav">
				<ul>
					<li class="single"><a>注册</a></li>
				</ul>
			</div>
			<div class="leftColumn" id="FoodTips">
				<img src="images/foodPoster.jpg" alt="彩绘食物" />
			</div>
			<div class="panel">
				<ul>
					<li><a>用户名</a><a id="UserNameTip" class="InputErrorTips"></a>
					</li>
					<li><input type="text" class="textBox" id="UserNameTextBox" />
					</li>
					<li><a>设置密码</a></li>
					<li><input class="textBox" id="PasswordTextBox"
						type="password" /></li>
					<li><a>送餐地址</a></li>
					<li><input class="textBox defaultTipInput" id="AddressTextBox"
						defaultTipID="AddressTextBoxDefaultTip" /></li>
					<li><a>手机号码</a><a id="PhoneNumTip" class="InputErrorTips"></a>
					</li>
					<li><input type="text" class="textBox" id="PhoneNumTextBox" />
					</li>
					<!-- <li><a title="获取验证码" id="GetCode" onclick="GetCode()">手机验证码</a><a
						id="GetCodeTip"></a>
					</li> 
					<li><input type="hidden" value="" id="AuthCode" />
					</li>
					<li style="margin-bottom:10px;">
						<ul id="CodeInput" style="display: none;">
							<li><input type="text" id="AuthCodeTextBox" class="textBox" />
							</li>
						</ul>
					</li>-->
					<li><a id="RegisterTips"></a></li>
					<li><input onclick="Register()" class="button" type="button"
						value="注          册 " /></li>
					<li><a href="_seller/sellerReg.jsp" 
						class="rule">   我是商家</a></li>
					<li><input name="ctl00$ContentPlaceHolder1$InviteUser"
						type="hidden" id="ContentPlaceHolder1_InviteUser" /></li>
				</ul>
			</div>
			<div id="locationChoose">
				<a class="close" title="关闭" onclick="CloseChoose()">关闭</a>
				<ul>
					<li><span>紫荆苑：</span> <a onclick="AddLocation('紫荆苑2号')">2号</a><a
						onclick="AddLocation('紫荆苑4号')">4号</a>
					</li>
					<li><span>刺桐苑：</span> <a onclick="AddLocation('刺桐苑1号')">1号</a><a
						onclick="AddLocation('刺桐苑2号')">2号</a> <a
						onclick="AddLocation('刺桐苑3号')">3号</a><a
						onclick="AddLocation('刺桐苑4号')">4号</a>
					</li>
					<li><span>凤凰苑：</span> <a onclick="AddLocation('凤凰苑1号')">1号</a><a
						onclick="AddLocation('凤凰苑2号')">2号</a> <a
						onclick="AddLocation('凤凰苑3号')">3号</a><a
						onclick="AddLocation('凤凰苑4号')">4号</a> <a
						onclick="AddLocation('凤凰苑5号')">5号</a>
					</li>
					<li><span>教学楼：</span> <a onclick="AddLocation('教学楼A区')">A区</a><a
						onclick="AddLocation('教学楼B区')">B区</a> <a
						onclick="AddLocation('教学楼C区')">C区</a><a
						onclick="AddLocation('教学楼D区')">D区</a> <a
						onclick="AddLocation('教学楼E区')">E区</a><a
						onclick="AddLocation('教学楼F区')">F区</a>
					</li>
				</ul>
			</div>
		</div>
		<%
			} else {
		%>
		<div class="midBody">
			<div class="secondNav">
				<ul>
					<li class="single"><a>登录</a></li>
				</ul>
			</div>
			<div class="contentBody">
				<div class="leftColumn" id="FoodTips">
					<img src="images/foodPoster.jpg" alt="彩绘食物" />
				</div>
				<div class="panel">
					<ul>
						<li><a>用户名/E-mail/手机号码</a><a id="UserNameTip"
							class="InputErrorTips"></a>
						</li>
						<li><input type="text" id="UserName"
							class="textBox defaultTipInput" defaulttipid="UserNameDefaultTip" />
						</li>
						<li><a>密码</a></li>
						<li><input type="password" id="Password" class="textBox"
							value="" />
						</li>
						<li></li>
						<li></li>
						<li><a id="LoginTip"></a>
						</li>
						<li><input type="button" class="button" value="登录"
							onclick="UserLogin()" /></li>
					</ul>
				</div>
				<script type="text/javascript">
					$(document).ready(function() {
						var userId = "UserName";

						$('#' + userId).setDefaultTip("用户名/E-mail/手机号码");

						$('#' + userId).focus(function() {
							WaiMai.ClearTips("UserNameTip");
							WaiMai.ClearTips("LoginTip");
						});
						$('input#Password').focus(function() {
							WaiMai.ClearTips("LoginTip");
						});

						$('input.textBox').keydown(function() {
							if (event.keyCode == 13) {
								UserLogin();
							}
						});
					});

					function UserLogin() {
						var tip = $('a#LoginTip');

						var userName = $('#UserName').val();
						if (userName == "") {
							tip.attr("class", "Error");
							tip.html("帐号不能为空");
							return;
						}
						if ($('a#UserNameTip').html() != "") {
							return;
						}

						var password = $('input#Password').val();
						if (password == "") {
							tip.attr("class", "Error");
							tip.html("密码不能为空");
							return;
						}

						tip.attr("class", "WaitingGray");
						tip.html("登录中……");
						$
								.ajax({
									type : "POST",
									url : "servlet/LoginServlet",
									contentType : "application/x-www-form-urlencoded; charset=UTF-8", //声明编码
									data : "userName=" + userName
											+ "&password=" + password,
									error : function(error) {
										var tip = $('a#LoginTip');
										tip.attr("class", "Error");
										tip.html("登录失败，请重试");
									},
									success : function(result) {
										var result = result.trim();
										var tip = $('a#LoginTip');
										if (result == "success") {
											//window.history.go(-1);
											window.location.href = document.referrer;//返回并刷新页面
											return;
										}
										if (result == "noSuchUser") {
											tip.attr("class", "Error");
											tip.html("查无此帐号");
											return;
										}
										if (result == "failed") {
											tip.attr("class", "Error");
											tip.html("帐号或密码错误");
											return;
										}
										tip.attr("class", "Error");
										tip.html("登录失败,请刷新重试");
									}
								});
					}
				</script>
				<%
					}
				%>
			</div>
		</div>
	</div>
	<jsp:include page="footer.jsp"></jsp:include>
</body>
</html>